import { handleSingleSeriesChartData } from '../echartUtils.js'
export function getRingOption(dataList) {
	let { seriesDataList, lengedDataList } = handleSingleSeriesChartData(dataList);
	let option = {
		"textStyle": {
			"fontFamily": "Source Han Sans CN"
		},
		"tooltip": {
			"show": false
		},
		"legend": {
			"show": true,
			"top": "center",
			"left": "45%",
			"orient": "vertical",
			"icon": "rect",
			"itemWidth": 8,
			"itemHeight": 8,
			"itemGap": 10,
			"type": "plain",
			"selectedMode": false,
			"data": lengedDataList,
			"formatter": (name) => {
				let temp = {},
					sumData = 0;
				seriesDataList.forEach(function(item, index) {
					sumData += Number(item.value);
					if (item.name == name) {
						temp = item;
					}
				});
				let percent = sumData == 0 ? 0 : (((temp.value) / sumData) * 100).toFixed(2);
				return `{name|${temp.name}} {percent|${percent}%}{value|${temp.value}}`;
			},
			"textStyle": {
				"rich": {
					"name": {
						"fontSize": 12,
						"width": "auto",
						"color": "#000",
						"fontFamily": "OPPOSans",
						"padding": [0,10, 0,10]
					},
					"value": {
						"fontSize": 12,
						"width": "auto",
						"color": "#000",
						"padding": [0, 10, 0, 0],
						"fontFamily": "OPPOSans",
						"align": "left"
					},
					"percent": {
						"fontSize": 12,
						"width": "auto",
						"color": "#000",
						"padding": [0, 10, 0, 0],
						"fontFamily": "OPPOSans",
						"align": "left"
					}
				}
			}
		},
		"series": [{
			"type": "pie",
			"color": ["#009CFF", "#00FFC6", "#F0AF39", "#FF6000", "#02E38A", "#7D8DFF", "#FA5858", "#00ACFF", "#9DFF86"],
			"selectedMode": "false",
			"startAngle": 90,
			"label": {
				"show": false,
				"position": "outside",
				"fontSize": 12,
				"color": "rgba(255, 255, 255, 0.6)",
				"fontWeight": "normal",
				"offset": [0, 0]
			},
			"emphasis": {
				"itemStyle": {
					"shadowBlur": 10,
					"shadowOffsetX": 0,
					"shadowColor": "rgba(0, 0, 0, 0.5)"
				}
			},
			"itemStyle": {
				"shadowOffsetX": 0,
				"shadowOffsetY": 0,
				"shadowBlur": 0,
				"shadowColor": "rgba(0, 43, 140, 0.42)",
				"borderColor": "#fff",
				"borderRadius": 0,
				"borderWidth": 0
			},
			"center": ["20%", "50%"],
			"radius": ["55%", "80%"],
			"data": seriesDataList
		}],
		"animation": true,
		"animationDuration": 1000,
		"animationEasing": "cubicOut",
		"animationDelay": 0
	}
	return option;
}